<template>
<div class="management-user-add views-container">
  <div class="wlm-form">
    <div class="wlm-form-header">添加用户</div>
    <div class="wlm-form-content">
      <el-form :ref="formFormatData.key" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="120px" class="retail-form" label-position="right">
        <el-form-item label="登录账号" prop="user_name">
          <el-input v-model.trim="formFormatData.formData.user_name">
          </el-input>
        </el-form-item>
        <el-form-item label="姓名" prop="real_name">
          <el-input v-model.trim="formFormatData.formData.real_name">
          </el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model.trim="formFormatData.formData.password">
          </el-input>
        </el-form-item>
        <!-- <el-form-item label="确认密码" prop="repassword">
          <el-input v-model.trim="formFormatData.formData.repassword">
          </el-input>
        </el-form-item> -->
      </el-form>
    </div>
  </div>
  <div v-cloak class="wlm-fixed-btn flex-row flex-align-c flex-justify-c">
    <el-button size="small" @click="formFormatSubmit({ router: { type: 'replace', path: '/user/managementAdminUser', code: 1 }})" type="primary">保存</el-button>
    <router-link tag="span" to="/user/managementAdminUser">
      <el-button size="small">返回</el-button>
    </router-link>
  </div>
</div>
</template>

<script>
// import { userAdd } from '@/api/user'
import {
  userAdd
} from '@/api/user'
import {
  regPhone,
  regPassword
} from '@/utils/regular'
import mixins from '@/mixins/mixins'
export default {
  mixins: [mixins.getters('Form')],
  name: 'ManagementUserAdd',
  components: {

  },
  directives: {

  },
  data() {
    var mobile = (rule, value, callback) => {
      if (!regPhone(value)) {
        return callback(new Error('注册手机号格式不正确'))
      } else {
        callback()
      }
    }

    var checkPwd = (rule, value, callback) => {
      if (!regPassword(value)) {
        return callback(new Error('密码格式错误'))
      } else {
        callback()
      }
    }
    // var checkPass = (rule, value, callback) => {
    //   if (value !== this.formFormatData.formData.password) {
    //     return callback(new Error('两次密码输入不一致'))
    //   } else {
    //     callback()
    //   }
    // }
    return {
      formFormatData: {
        key: 'userForm',
        api: {
          // editForm
          submitForm: userAdd
        },
        formData: {
          real_name: '',
          password: '',
          repassword: '',
          user_name: ''
        },
        rules: {
          real_name: [{
            required: true,
            message: '请输入真实姓名',
            trigger: 'blur'
          }],
          password: [{
            required: true,
            message: '请输入密码',
            trigger: 'blur'
          },
          {
            validator: checkPwd,
            trigger: 'blur'
          }
          ],
          // repassword: [{
          //   required: true,
          //   message: '请输入确认密码',
          //   trigger: 'blur'
          // },
          // {
          //   validator: checkPass,
          //   trigger: 'blur'
          // }
          // ],
          user_name: [{
            required: true,
            message: '请输入用户手机号',
            trigger: 'blur'
          },
          {
            validator: mobile,
            trigger: 'blur'
          }
          ]
        }
      }
    }
  },
  methods: {

  }
}
</script>

<style lang="scss" scoped>
.management-user-add {}
</style>
